package com.admin.controller;

import java.util.List;

import com.admin.model.SysBootScreen;
import com.admin.util.Page;
import com.admin.util.UtilTools;

public class SysBootScreenController extends BaseController {
	public static String TOBOOTSCREEN = "/sysBootScreen";
	// 图片列表
	public void index() {
		try {
			/*List<SysBootScreen> list = SysBootScreen.dao.list();
			setAttr("list", list);*/
			// 处理查询条件
			SysBootScreen sysBootScreen = getModel(SysBootScreen.class);
			String title = sysBootScreen.get("title");
			String stitle = null;
			if(UtilTools.isNotNull(title)){
				stitle = "title like '%"+ title +"%'";
			}
			Integer type = sysBootScreen.get("is_release");
			String stype = null;
			if(UtilTools.isNotNull(type)){
				stype = "is_release = '"+ type +"'";
			}
			// 处理分页参数
			Page<SysBootScreen> page = new Page<SysBootScreen>(getPara("pageCurrent"),getPara("pageSize"));
			page.setOrderField("show_number");
			page.setOrderDirection("asc");
			SysBootScreen.dao.listByPage(new String[]{stitle,stype},page);
			setAttr("page",page);
			render("/jsp/sysBootScreen/list.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getMessage(), e);
		}
	}

	// 跳往添加
	public void toAdd() {
		try {
			render("/jsp/sysBootScreen/add_photo.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getMessage(), e);
		}
	}

	// 跳往修改
	public void toUpdate() {
		try {
			String id = getPara("id");
			SysBootScreen sysBootScreen = SysBootScreen.dao.getSysBootScreenById(id);
			setAttr("sysBootScreen", sysBootScreen);
			render("/jsp/sysBootScreen/add.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getMessage(), e);
		}
	}

	// 保存
	public void doAdd() {
		try {
			SysBootScreen sysBootScreen = getModel(SysBootScreen.class);
			if (null == sysBootScreen.get("id")) {
				sysBootScreen.set("flag", 1);
				sysBootScreen.save();
			} else {
				sysBootScreen.update();
			}
			ajax(Status.success,TOBOOTSCREEN,true);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getMessage(), e);
			ajax(Status.error,null,null);
		}
	}

	// 删除
	public void del() {
		try {
			SysBootScreen.dao.del(getParaValues("ids"));
			renderJson(ajax(Status.success, "删除成功"));
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e.getMessage(), e);
			renderJson(ajax(Status.error, "删除失败"));
		}
	}
}
